home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / program / wintech1.zip / PETZOLD.ZIP / DRAWING.C next >
C/C++ Source or Header  |  1991-11-06  |  2KB  |  82 lines

  1. /*----------------------------------------
  2.    DRAWING.C -- Drawing on the Dialog Box
  3.                 (c) Charles Petzold, 1991
  4.   ----------------------------------------*/
  5.  
  6. #include <windows.h>
  7. #include <string.h>
  8. #include "drawing.h"
  9.  
  10. BOOL FAR PASCAL DlgProc (HWND, WORD, WORD, LONG) ;
  11.  
  12. char szAppName [] = "Drawing" ;
  13.  
  14. int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
  15.                     LPSTR lpszCmdLine, int nCmdShow)
  16.      {
  17.      DialogBox (hInstance, szAppName, NULL,
  18.           MakeProcInstance (DlgProc, hInstance)) ;
  19.  
  20.      return 0 ;
  21.      }
  22.  
  23. BOOL FAR PASCAL DlgProc (HWND hwnd, WORD message, WORD wParam, LONG lParam)
  24.      {
  25.      static char szBuffer [32] ;
  26.      static int  cxFont, cyFont ;
  27.      static RECT rect ;
  28.      DWORD       dwDlgBaseUnits ;
  29.      HDC         hdc ;
  30.      HWND        hwndRect ;
  31.      PAINTSTRUCT ps ;
  32.  
  33.      switch (message)
  34.           {
  35.           case WM_INITDIALOG:
  36.                dwDlgBaseUnits = GetDialogBaseUnits () ;
  37.                cxFont = LOWORD (dwDlgBaseUnits) ;
  38.                cyFont = HIWORD (dwDlgBaseUnits) ;
  39.  
  40.                wsprintf (szBuffer, "Base Units: %d x %d", cxFont, cyFont) ;
  41.                SetDlgItemText (hwnd, ID_TEXT, szBuffer) ;
  42.  
  43.                hwndRect = GetDlgItem (hwnd, ID_RECT) ;
  44.                GetWindowRect (hwndRect, &rect) ;
  45.                ScreenToClient (hwnd, (LPPOINT) &rect.left) ;
  46.                ScreenToClient (hwnd, (LPPOINT) &rect.right) ;
  47.  
  48.                SetWindowLong (hwndRect, GWL_STYLE, ~WS_VISIBLE &
  49.                     GetWindowLong (hwndRect, GWL_STYLE)) ;
  50.  
  51.                return TRUE ;
  52.  
  53.           case WM_ERASEBKGND:
  54.                if (IsIconic (hwnd))
  55.                     return TRUE ;
  56.  
  57.                break ;
  58.  
  59.           case WM_PAINT:
  60.                hdc = BeginPaint (hwnd, &ps) ;
  61.  
  62.                if (IsIconic (hwnd))
  63.                     {
  64.                     DrawIcon (hdc, 0, 0, LoadIcon (NULL, IDI_APPLICATION)) ;
  65.                     }
  66.                else
  67.                     {
  68.                     TextOut (hdc, 2 * cxFont, cyFont, szBuffer,
  69.                              strlen (szBuffer)) ;
  70.                     DrawText (hdc, szBuffer, -1, &rect, DT_CENTER) ;
  71.                     }
  72.  
  73.                EndPaint (hwnd, &ps) ;
  74.                return TRUE ;
  75.  
  76.           case WM_CLOSE:
  77.                EndDialog (hwnd, 0) ;
  78.                return TRUE ;
  79.           }
  80.      return FALSE ;
  81.      }
  82.